Component({
  /**
   * 组件的属性列表
   */
  properties: {
    assign: {
      type: Boolean,
      value: false
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    list: [
      {
        icon: '/assets/main/toilet.png',
        text: '清洗厕所马桶',
        dropdown: false,
        responsible: [
          {
            name: '小周',
            avartar: '/assets/chat/member1.png'
          }
        ],
        showAdd: true
      },
      {
        icon: '/assets/main/clean2.png',
        text: '打扫厕所下水道',
        dropdown: false,
        responsible: [
          {
            name: '小何',
            avartar: '/assets/chat/member4.png'
          },
          {
            name: '小林',
            avartar: '/assets/chat/member3.png'
          }
        ],
        showAdd: true
      },
      {
        icon: '/assets/main/trash.png',
        text: '扔垃圾',
        dropdown: false,
        responsible: [
          {
            name: '小陈',
            avartar: '/assets/chat/member2.png'
          }
        ],
        showAdd: true
      }
    ],
    members: [
      {
        name: '小周',
        avartar: '/assets/chat/member1.png'
      },
      {
        name: '小陈',
        avartar: '/assets/chat/member2.png'
      },
      {
        name: '小林',
        avartar: '/assets/chat/member3.png'
      },
      {
        name: '小何',
        avartar: '/assets/chat/member4.png'
      }
    ],
    showSelector: false, 
    currentTaskId: null, 
    list2: [
      {
        icon: '/assets/main/toilet.png',
        text: '清洗厕所马桶'
      },
      {
        icon: '/assets/main/clean2.png',
        text: '打扫宿舍地板'
      },
      {
        icon: '/assets/main/shower.png',
        text: '清洗厕所卫浴'
      },
      {
        icon: '/assets/main/box.png',
        text: '帮助舍友取快递'
      }
    ]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    returnAssign(){
      this.changeToAssign1();
    },
    toggleDropDown(e) {
      const index = e.currentTarget.dataset.index;
      const list = this.data.list;
      if (index >= 0 && index < list.length) {
        list[index].dropdown = !list[index].dropdown;
        this.setData({ list });
      }
    },
    saveInput(e) {
      const index = e.currentTarget.dataset.index;
      const value = e.detail.value.trim();
      const list = this.data.list;
      if (value) {
        list[index].text = value;
      }
      list[index].editing = false;
      list[index].dropdown = false;
      this.setData({ list });
    },
    selectItem(e){
      const index = e.currentTarget.dataset.index; 
      const selectedValue = e.currentTarget.dataset.value; 
      const list = this.data.list;
      if (index >= 0 && index < list.length) {
        list[index].text = selectedValue; 
        list[index].dropdown = false; 
        this.setData({ list }); 
      }
    },
    returnAssign(){
      this.triggerEvent('changeAssign', { assign: true });
    }
  }
})